<style>
	#name {width: 400px;}
	#days_end {width: 125px;}
</style>

<?php
$peer = OrdersPeer::getInstance();
$id = Zend_Controller_Front::getInstance()->getRequest()->getParam('id');
$order = $peer->find($id)->current();
if (!$order) $order = OrdersPeer::getInstance()->createRow();


$form = $this->element;

if ($form->getRow()) {
	$productRow = $form->getRow()->getRow();
} else {
	$productRow = ProductPeer::getInstance()->createRow();
}

foreach ($form->getElements() as $e) {
	if ($e instanceof Zend_Form_Element_Checkbox) {
		$label = $e->getDecorator('Label');
		$label->setOption('placement', Zend_Form_Decorator_Abstract::APPEND);
		$label->setTag('dd');

		$tag = $e->getDecorator('HtmlTag');
		$tag->setTag('dt');
		//$e->removeDecorator('Label');
		//$e->addDecorator($label);

		//echo '<pre>';
		//var_dump($e->getDecorators());die();
	}
}

function getMonthsByAge($yearsByMonth, $currentMonth = '') {
	$str = '';
	$helper = new Helpers_PluralMonths();
	for ($month = 0, $year = 1; $month < $yearsByMonth;) {
		if ($month < 23) {
			++$month;
		} else {
			$month = ++$year*12;
		}
		
		$selected = '';
		if ($currentMonth == $month) {
			$selected = 'selected="selected"';
		}
		$str .= '<option value="'.$month.'" '.$selected.'>'.$helper->pluralMonths($month).'</option>';
	}
	
	return $str;
}

?>

<link rel="stylesheet" media="screen" href="http://<?php echo Config::getInstance()->default->hostname; ?>/style/admin_product.css" />
<form enctype="multipart/form-data" method="post" action="">
  <div>

    <?php
    /**
     * Translate some form errrors.
     *
     * @param string $key
     * @param string $error
     * @return string
     */
    function _translate($key, $error)
    {
    	$_translated = array(
			'isEmpty' => 'Поле обязательно для заполнения',
		);

    	if (isset($_translated[$key])) {
    		return $_translated[$key];
    	}

    	return $error;
    }

    $errors = $form->getMessages();
    foreach ($errors as $key => $error) {
    	if (is_array($error)) {
    		unset($errors[$key]);
    	}

   		if (is_array($error)) {
     		foreach ($error as $k => $v) {
     			$label = $form->getElement($key)->getLabel();
     			$v = _translate($k, $v);
     			$errors[$key][$k] = "$label -- $v";
     		}
    	} else {
    		$errors[$key] = _translate($key, $error);
    	}
    }

    if ($errors) {
	    echo "<ul class='errors'>";
	    foreach ($errors as $error) {
	    	if (is_array($error)) {
	    		foreach ($error as $k => $v) {
	    			echo "<li>$v</li>";
	    		}
	    	} else {
	    		echo "<li>$error</li>";
	    	}
	    }
	    echo "</ul>";
    }
    ?>

    <fieldset>
      <legend>Популярные</legend>
	    <dl class="floater-4">
        <?php echo $form->getElement('priority'); ?>
      </dl>
      <dl class="floater-4">
        <?php echo $form->getElement('price'); ?>
      </dl>
      <dl class="floater-4">
       	<?php echo $form->getElement('rating'); ?>
      </dl>
      <dl class="floater-4">
           <?php $e = $form->getElement('count');
	            $e->setAttrib('maxlength', 40);
	            echo $e;
	      ?>
      </dl>
      <dl class="floater-4">
       <?php echo $form->getElement('sales_count'); ?>
      </dl>
      <dl>
      	<?php echo $form->getElement('tag2product'); ?>
      </dl>

      <dl class="addtag">
      	<br>
      	<div><b>Добавить теги</b></div>
      	<select class="crud_listbox" multiple name="add_tag[]" id="add_tag[]">
      		<option value=''></option>
      		<?php
      		$tagsRows = TagPeer::getInstance()->fetchAll();
      		foreach($tagsRows as $tag){
      			echo "<option value='".$tag->getId()."'>".$tag->getName()."</option>";
      		}
      		?>
      		
      	</select>
      </dl>

    </fieldset>


    <fieldset>
      <legend>Основные</legend>


    <dl class="floater-4">
      <?php $e = $form->getElement('internal_id');
      if ($e) $e->setAttrib('size', 15); echo $e; ?>
    </dl>
    <dl class="floater-4">
      <?php echo $form->getElement('file_image'); ?>
    </dl>


    <dl>
      <?php echo $form->getElement('name'); ?>
      <!--dt id="translated_url-label">
        <label for="translated_url" class="optional">Название страницы для URL</label>
      </dt>
      <dd id="translated_url-element">
        <input type="text" name="translated_url" id="translated_url" value="nabor_ukras_mobilnik_hanna_montana" maxlength="255" size="128">
      </dd-->
    </dl>
    <dl class="floater-3">
      <?php echo $form->getElement('brand_id'); ?>
    </dl>
	<div class="clearfix"></div>
	<dl class="floater-2">
       <?php echo $form->getElement('country_id'); ?>
    </dl>
	<dl  class="floater-4 floats" style='margin-top: 28px; font-weight:bold;width:180px;'>
    	<?php echo $form->getElement('manufacturer_warranty'); ?>
    </dl>
	<dl class="floater-5">
       <?php echo $form->getElement('days_end'); ?>
    </dl>
    <div class="clearfix"></div>
	<div style="padding-top: 20px">
    <dl class="floater-3">
		 <label><b>Возраст от:</b></label>
	       <select id='age_from' name="age_from" style="width: 80px;">
					<option value=''>не важно</option>
					<option value='0' <?php if($productRow->getFromBorn()){echo 'selected="selected"';}?>>c рождения</option>
				    <?php echo getMonthsByAge(12*20, $form->getValue('age_from')); ?>
		     </select>
		     <label><b>Возраст до:</b></label>
				 <select id='age_to' name="age_to" style="width: 80px;">
						<option value='255'>не важно</option>
					    <?php echo getMonthsByAge(12*20, $form->getValue('age_to')); ?>
			   </select>
    </dl>
	<dl class="floater-3">
      <label><b>Пол:</b></label>
		      <!-- <span style="color: red; padding-left: 4px;">*</span>-->
		       <select style="width: 80px;" id="gender" name="gender">
			       <?php
			        if($form->getValue('gender') == 0){
			            echo "<option selected='selected' value='0'>Неважно</option>";
			        }else{
			            echo "<option value='0'>Неважно</option>";
		            }
		            if($form->getValue('gender') == 1){
			            echo "<option selected='selected' value='1'>Мужской</option>";
			        }else{
			            echo "<option value='1'>Мужской</option>";
		            }
			        if($form->getValue('gender') == 2){
			            echo "<option selected='selected' value='2'>Женский</option>";
			        }else{
			            echo "<option value='2'>Женский</option>";
		            }
		       ?>
		       </select>
    </dl>
	</div>
    <div class="clearfix"></div>
    
    <dl  class="floater-3" style="padding-top: 13px;">
    	Вы выбрали товары, принадлежащие к разным категориям. Если нужно указать для них новую - укажите ее в дереве. В противном случае - не делайте изменений в дереве
       <?php echo $form->getElement('product2product_category'); ?>
       
       
       
       <?php echo $form->getElement('full_desc'); ?>
      </dl>
      
      
      
      <div class="clearfix"></div>

      <dl class="floater-3">
		<?php 
		 $form->getElement('synonims')->setAttrib("class", "");
		echo $form->getElement('synonims'); ?>
      </dl>
      <dl class="floater-3">
        <?php 
         $form->getElement('additional_text')->setAttrib("class", "");
        echo $form->getElement('additional_text'); ?>
      </dl>



      <div class="clearfix">      </div>
      </fieldset>
	<fieldset>
		<legend>Отображать на промо-сайте со след вариантами</legend>
	<dl class="floater-5">
		<?php echo $form->getElement('ny_index'); ?>
	  </dl>
	<dl class="floater-5">
		<?php echo $form->getElement('ny_twohundred'); ?>
	  </dl>
	<dl class="floater-5">
		<?php echo $form->getElement('ny_top10_boy'); ?>
	  </dl>
	<dl class="floater-5">
		<?php echo $form->getElement('ny_top10_gerl'); ?>
	  </dl>

	<dl class="floater-5">
		<?php echo $form->getElement('ny_top10_baby'); ?>
	  </dl>
	<dl class="floater-5">
		<?php echo $form->getElement('ny_top10_active'); ?>
	  </dl>
	 </fieldset>
<!-- **************************************************************************-->
	<fieldset>
        <legend>Признаки</legend>
    <dl class="floater-5">
        <?php echo $form->getElement('is_hit'); ?>
      </dl>
	<dl class="floater-5">
        <?php echo $form->getElement('is_new'); ?>
      </dl>
	<dl class="floater-5">
        <?php echo $form->getElement('is_sale'); ?>
      </dl>
	<dl class="floater-5">
        <?php echo $form->getElement('is_discout'); ?>
      </dl>

	<dl class="floater-5">
        <?php echo $form->getElement('is_recommended'); ?>
      </dl>
	<dl class="floater-5">
        <?php echo $form->getElement('is_brand'); ?>
      </dl>
	 </fieldset>
<!-- ****************************************************************************-->

    <fieldset>
      <legend>Характеристики</legend>
      <dl class="floater-4">
	      <?php $e = $form->getElement('weight');
	            $e->setAttrib('maxlength', 40);
	            echo $e;
	      ?>

      </dl>
      <dl class="floats topped" style="width: 140px;">
        <?php echo $form->getElement('is_bulky'); ?>
      </dl>

      <dl class="floater-4">
        <?php echo $form->getElement('size'); ?>
      </dl>
      <dl class="floater-4">
        <?php echo $form->getElement('material'); ?>
      </dl>
      <dl class="floater-4">
        <?php echo $form->getElement('dimension'); ?>
      </dl>
      <dl class="floater-4">
        <?php echo $form->getElement('color'); ?>
      </dl>
      <div class="clearfix"></div>
      <dl class="floater-4">
        <?php echo $form->getElement('file_certificate'); ?>
      </dl>
      <dl class="floater-4">
        <?php echo $form->getElement('file_rules'); ?>
      </dl>
      <dl class="floater-4">
        <?php echo $form->getElement('file_instruction'); ?>
      </dl>
	  <dl class="floater-4">
        <?php echo $form->getElement('file_video'); ?>
      </dl>
	  <dl class="floater-4">
        <?php echo $form->getElement('file_swf'); ?>
      </dl>

    </fieldset>

<!--     <fieldset>
      <legend>Сопутствующие и похожие товары</legend>
      <dl>
        <?php echo $form->getElement('alike'); ?>
      </dl>
      <dl>
        <?php echo $form->getElement('attendant'); ?>
      </dl>
    </fieldset>   -->
    <dl>
      <?php echo $form->getElement('parent_id'); ?>
      <?php echo $form->getElement('subproducts_count'); ?>
      <?php echo $form->getElement('internal_comment'); ?>
      </dl>
      <dl class="floats">
        <?php echo $form->getElement('is_active'); ?>
      </dl>
      <dl style="clear:both">
      <dt id="submit-label">
        &nbsp;
      </dt>
      <dd id="submit-element">
        <input type="submit" name="submit" id="submit" value="Сохранить">
      </dd>
      
      <?php echo $form->getElement('crud_exit'); ?>
    </dl>
  </div>
</form>
